package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * ClassName: DishMapper
 * Package: com.sky.mapper
 * Description:
 *
 * @Author yangkx
 * @Create 2024/5/8 15:00
 * @Version 1.0
 */
@Mapper
public interface DishMapper {
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(@Param("categoryId") Long id);

    //这里用xml的形式写sql语句，要实现主键返回,记得公共字段自动填充!
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    //用xml的形式写sql语句，要实现dto查询dish并且封装为dishVO
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where id = #{id}")
    Dish getById(@Param("id") Long id);

    @Delete("delete from dish where id = #{id}")
    void deleteById(@Param("id") Long id);

    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getListByCategoryId(@Param("categoryId") Long categoryId);

    @Select("select * from dish where category_id = #{categoryId} and status = #{status}")
    List<Dish> list(Dish dish);

    Integer countByMap(Map map);
}
